import { httpRequest } from "../httpRequest"
import type { IRes, IResWithPage } from "../types"
import type { IQuestion } from "@shared/types/question"

export const questionApi = {
    getQuestionList(params: {
        page?: number;
        pageSize?: number;
        type?: string;
        difficulty?: string;
        keyword?: string;
        creator?: string;
    }): IResWithPage<IQuestion[]> {
        return httpRequest.get('/api/v1/question/list', { params })
    },
    getQuestionDetail(id: string): IRes<IQuestion> {
        return httpRequest.get('/api/v1/question/detail', {
            params: { id }
        })
    },
    createQuestion(data: Omit<IQuestion, '_id' | 'create_time' | 'creator'>): IRes<IQuestion> {
        return httpRequest.post('/api/v1/question/create', data)
    },
    updateQuestion(data: Partial<IQuestion> & { id: string }): IRes<IQuestion> {
        return httpRequest.post('/api/v1/question/update', data)
    },
    deleteQuestion(id: string): IRes<null> {
        return httpRequest.post('/api/v1/question/delete', { id })
    },
    batchDeleteQuestion(ids: string[]): IRes<{ deletedCount: number }> {
        return httpRequest.post('/api/v1/question/delete', { ids })
    },
    importQuestions(questions: Omit<IQuestion, '_id' | 'create_time' | 'creator'>[]): IRes<{ importedCount: number }> {
        return httpRequest.post('/api/v1/question/import', { questions })
    },
    exportQuestions(params: {
        type?: string;
        difficulty?: string;
        creator?: string;
    }): IRes<IQuestion[]> {
        return httpRequest.get('/api/v1/question/export', { params })
    }
}